
package Test;

import java.io.File;

import junit.framework.TestCase;
import svgedit.gui.Frame;
import svgedit.gui.controlpoints.CircleRadiusControlPoint;
import svgedit.svg.SVGCircleElement;
import svgedit.svg.SVGElement;

/**
 *  Test case when resize an element and test when undo this execution
 *
 */
public class ResizeElementTest extends TestCase {

	/**
	 *  Get Frame object
	 * */
	private static Frame frame;
	/**
	 *  Choose a circle element which is going to be resized
	 * */
	private SVGCircleElement selectedElem;
	
	/**
	 *  Circle point control object
	 * */
	private CircleRadiusControlPoint control;
	
	/**
	 *   Backup the control X and Y
	 * */
	private float backupX;
	private float backupY;
	
	
	/**
	 *   Constructor for resizeElement test
	 * */
	public ResizeElementTest(String arg0) {
		super(arg0);
		frame = new Frame();
		File file = new File("src/testfile/test.svg");
        frame.openFile(file);
        selectedElem = getSelectedElement();
        control = new CircleRadiusControlPoint(selectedElem);
        backupX = control.getX();
        backupY = control.getY();
        
	}
	
	/**
	 *   Get a circle element in this file
	 *   
	 *   @return elem to get the selected item
	 * */
	public SVGCircleElement getSelectedElement(){
		for (SVGElement elem: frame.getDocument()){
			if (elem instanceof SVGCircleElement && elem.getParent() == frame.getDocument().getRootGroup()){
				return (SVGCircleElement)elem;
			}
		}
		return null;
	}
	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();	
	}
	
	/**
	 *  Test unit when resize an element
	 * */
	public void testReizeElementTest(){
		ResizeElement(control);
	}
	
	/**
	 *  Test unit when undo the reize execution
	 * */
	public void testUndoResizeElementTest(){
		undoResizeElement(control);
	}
	
	/**
	 *  Undo the resizing operation to recover its original size
	 *  
	 *  @param control to get the circle control point
	 * */
	public void undoResizeElement(CircleRadiusControlPoint control){
		float expectedX = backupX;
		control.set(backupX, backupY);
		float actualX = control.getX();

	    assertEquals(expectedX,actualX);
	}
	
	/**
	 *  Resize the selected element size
	 *  
	 *  @param control to get the circle control point
	 * */
	public void ResizeElement( CircleRadiusControlPoint control){
		float expectedX = 300.0f;
		float expectedY = 200.0f;
		control.set(expectedX, expectedY);
		
		float actualX = control.getX();
		assertEquals(expectedX,actualX);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

}
